package com.ts.code.creator.creator.impl;

import com.ts.code.creator.enums.CreateFileEnum;
import com.ts.code.creator.express.ExpressContext;
import com.ts.code.creator.express.ExpressUtil;
import com.ts.code.creator.util.CreateCodeContext;

/**
 * 聚合层 controller
 */
public class AdminServiceCreator extends AbstractCodeCreator {

    public AdminServiceCreator(CreateCodeContext context) {
        super(context);
    }

    @Override
    protected CreateFileEnum createFileEnum() {
        return CreateFileEnum.ADMIN_SERVICE;
    }

    @Override
    public void doCreate() {
        // 聚合层 service
        addMethod(classFileSearch.adminService(), adminService(context));
    }

    private String adminService(CreateCodeContext context) {
        String text = remark("param") +
                "    ${returnType} ${methodName}(${paramStr});";

        // 参数
        String paramStr = adminParam();

        ExpressContext expressContext = new ExpressContext();
        expressContext.put(context);
        expressContext.put("returnType", adminVO());
        expressContext.put("paramStr", paramStr);
        return ExpressUtil.eval(text, expressContext);
    }

}
